﻿using gregn6Lib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;

namespace XYX.Print.Utils.GridReport
{

    #region 注册Grid++Report
    public class GridReportReg1
    {

        [System.Runtime.InteropServices.DllImport("grdes6.dll")]
        public static extern int DllRegisterServer();

        [System.Runtime.InteropServices.DllImport("grdes6.dll")]
        public static extern int DllUnregisterServer();
        /// <summary>
        /// 判断上面文件是否注册成功
        /// </summary>
        /// <param name="allowShow">是否允许弹出注册成功的提示</param>
        public static int Register(bool allowShow)
        {
           
            int isRegisterSucceed = DllRegisterServer();

            if (isRegisterSucceed >= 0)
            {
                if (allowShow)
                {
                    //SUCCESS
                }
            }
            else
            {
                if (allowShow)
                {
                    //ERROR
                }
            }
            return isRegisterSucceed;
        }
    }

    public class GridReportReg2
    {
        [System.Runtime.InteropServices.DllImport("gregn6.dll")]
        public static extern int DllRegisterServer();

        [System.Runtime.InteropServices.DllImport("gregn.dll")]
        public static extern int DllUnregisterServer();
        /// <summary>
        /// 判断上面文件是否注册成功
        /// </summary>
        /// <param name="allowShow">是否允许弹出注册成功的提示</param>
        public static int Register(bool allowShow)
        {
           
            int isRegisterSucceed = DllRegisterServer();

            if (isRegisterSucceed >= 0)
            {
                if (allowShow)
                {
                    //SUCCESS
                }
            }
            else
            {
                if (allowShow)
                {
                    //ERROR
                }

            }
            return isRegisterSucceed;
        }
    }
    /// <summary>
    /// 调用注册的联合类,
    /// </summary>
    public class GridReportReg3
    {
        /// <summary>
        /// 注册打印com dll组件类 注意它已写好判断是否已注册的内容,如果已注册了,他会不执行,(他先 grproLib.GridppReport Report = new grproLib.GridppReport(); new一下报错则没有注册,则运行注册的代码 )
        /// </summary>
        /// <param name="allowShow">是否允许弹出注册是否成功的信息</param>
        /// <returns></returns>
        public static int Register(bool allowShow)
        {
          
            if (isRegisted())
            {
                return 10;
            }
            else
            {
                int a = GridReportReg1.Register(allowShow);
                int b = GridReportReg2.Register(allowShow);
                return a + b;
            }
        }

        /// <summary>
        /// 是否已注册
        /// </summary>
        /// <returns>返回是否已注册</returns>
        static bool isRegisted()
        {
            bool isRegistry = true;
            try
            {
                GridppReport Report = new GridppReport();
                Report = null;
            }
            catch (Exception)
            {
                isRegistry = false;
            }
            GC.Collect();
            return isRegistry;
        }
    }
    #endregion
}
